﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// 文件名：ClsSystemSetDAL.cs
/// 作  者：黄 纲
/// 时  间：2007.01.15
/// 说  明：ClsSystemSetDAL类用户系统设置相关处理
/// </summary>
public class ClsSystemSetDAL
{
	/// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取系统参数设置数据集
    /// </summary>
    /// <param name="Type"></param>
    /// <returns></returns>
    public DataSet GetSystemParamSetDataSet(int Type)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("GetSystemParamSetDataSet", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 获取系统参数设置
    /// </summary>
    /// <param name="Type"></param>
    /// <returns></returns>
    public string GetSystemParamSetText(int Type)
    {
        DataSet dst = new DataSet();
        StringBuilder str = new StringBuilder();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("GetSystemParamSetDataSet", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@type", SqlDbType.Int, 4);
        dat.SelectCommand.Parameters["@type"].Value = Type;

        try
        {
            dat.Fill(dst);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                str.Append(dst.Tables[0].Rows[0][2].ToString() + "|");
                str.Append(dst.Tables[0].Rows[0][3].ToString() + "|");
                str.Append(dst.Tables[0].Rows[0][4].ToString() + "|");
                str.Append(dst.Tables[0].Rows[0][5].ToString() + "|");
                str.Append(dst.Tables[0].Rows[0][6].ToString() + "|");
                str.Append(dst.Tables[0].Rows[0][7].ToString());
            }
            else
            {
                str.Append("");
            }
        }
        catch
        {
            str.Append("");
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return str.ToString();
    }

    /// <summary>
    /// 修改系统参数设置
    /// </summary>
    /// <param name="Type"></param>
    /// <param name="Is_set1"></param>
    /// <param name="Is_set2"></param>
    /// <param name="Count1"></param>
    /// <param name="Count2"></param>
    /// <param name="Set_type1"></param>
    /// <param name="Set_type2"></param>
    /// <returns></returns>
    public Boolean UpdateSystemSet(int Type, bool Is_set1, bool Is_set2, string Count1, string Count2, int Set_type1, int Set_type2)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpdateSystemSet", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;
        com.Parameters.Add("@is_set1", SqlDbType.Bit, 1);
        com.Parameters["@is_set1"].Value = Is_set1;
        com.Parameters.Add("@is_set2", SqlDbType.Bit, 1);
        com.Parameters["@is_set2"].Value = Is_set2;
        com.Parameters.Add("@set_count1", SqlDbType.NVarChar, 50);
        com.Parameters["@set_count1"].Value = Count1;
        com.Parameters.Add("@set_count2", SqlDbType.NVarChar, 50);
        com.Parameters["@set_count2"].Value = Count2;
        com.Parameters.Add("@set_type1", SqlDbType.Int, 4);
        com.Parameters["@set_type1"].Value = Set_type1;
        com.Parameters.Add("@set_type2", SqlDbType.Int, 4);
        com.Parameters["@set_type2"].Value = Set_type2;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// TextBox控件非空验证
    /// </summary>
    /// <param name="TextBoxArray">TextBox控件数组</param>
    /// <returns></returns>
    public string FieldValidator(ArrayList TextBoxArray)
    {
        string strReturnValue = "";

        IEnumerator ienumer = TextBoxArray.GetEnumerator();

        while (ienumer.MoveNext())
        {
            TextBox txtbox = (TextBox)ienumer.Current;

            if (txtbox.Text.Trim() == "")
            {
                strReturnValue = txtbox.ToolTip + "不能为空！";

                break;
            }
        }

        return strReturnValue;
    }

    /// <summary>
    /// 自定义TextBox控件时间非空和格式验证
    /// </summary>
    /// <param name="DateTimeArray">自定义TextBox控件数组</param>
    /// <returns></returns>
    public string DateTimeValidator(ArrayList DateTimeArray)
    {
        string strReturnValue = "";

        IEnumerator ienumer = DateTimeArray.GetEnumerator();

        while (ienumer.MoveNext())
        {
            //CuTextSelectBox txtbox = (CuTextSelectBox)ienumer.Current;

            //if (txtbox.Text.Trim() == "")
            //{
            //    strReturnValue = txtbox.ToolTip + "时间不能为空！";

            //    break;
            //}
            //else
            //{
            //    try
            //    {
            //        DateTime dateTime = DateTime.Parse(txtbox.Text.Trim());
            //    }
            //    catch
            //    {
            //        strReturnValue = txtbox.ToolTip + "时间格式不正确！";

            //        break;
            //    }
            //}
        }

        return strReturnValue;
    }
}
